package com.fit4as.util.reflect
{

public class Method
{
    public var name : String;
    private var declaringClass : Class;
    private var parameterTypes : Array;

    public function Method( declaringClass : Class, name : String, parameterTypes : Array = null )
    {
        this.declaringClass = declaringClass;
        this.name = name;
        this.parameterTypes = parameterTypes;
    }

    public function invoke(target : Object, params : Array) : *
    {
        //t race("Method#invoke " + [target, name, params]);
        return target[ name ].apply(target, params);
    }

    public function getName() : String
    {
        return name;
    }

    public function getReturnType() : Class
    {
    	return ClassUtil.getMethodReturnType( declaringClass, name );
    }

    public function getParameterTypes() : Array
    {
        if( parameterTypes == null ) parameterTypes = ClassUtil.getMethodParameterTypes( declaringClass, name );
        return parameterTypes;
    }
    

	private var componentType : Class;

	public function setComponentType( type : Class ) : void
	{
		this.componentType = type;
	}
	
	public function getComponentType() : Class
	{
		return componentType;
	}    
	
}
}